package pl.koziczak.knowledgeintegration.xml;

import java.io.File;
import java.io.IOException;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;

import org.w3c.dom.Document;
import org.xml.sax.SAXException;

import pl.koziczak.knowledgeintegration.exception.KnowledgeIntegrationException;

public class XMLReader implements IXMLReader {

	public Document prepareDocument(File xmlFile) throws KnowledgeIntegrationException {
		Document document = null;
		try {
			DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
//			docBuilderFactory.setIgnoringElementContentWhitespace(false);
//			docBuilderFactory.setIgnoringComments(true);
			DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
			document = docBuilder.parse(xmlFile);
		} catch (ParserConfigurationException e) {
			throw new KnowledgeIntegrationException(e);
		} catch (SAXException e) {
			throw new KnowledgeIntegrationException(e);
		} catch (IOException e) {
			throw new KnowledgeIntegrationException(e);
		}
		
		return document;
	}
}
